Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark which attributes of the image should be considered content #43280

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

oandregal
Copy link
Member

@oandregal oandregal commented Aug 16, 2022

Related #43037 #43038

This PR marks which attributes of the image block should be considered content. This affects two features:

  • The ongoing Add: Content lock ability. #43037 By adding these markers the image block will be listed in the ListView when the "content lock" is active.
  • The "transform to patterns" feature. This PR changes how certain fields are treated.
    • Before: all user-edited attributes are migrated, including style ones such as border radius.
    • After: only the content attributes of the block are migrated.
Before (the radius set by the user is maintained) After (the radius set by the user is ignored)
Gravacao.de.ecra.a.partir.de.16-08-2022.18.58.30.webm
Gravacao.de.ecra.a.partir.de.16-08-2022.19.00.40.webm

@oandregal oandregal requested a review from ajitbohra as a code owner August 16, 2022 17:11
@oandregal oandregal self-assigned this Aug 16, 2022
@oandregal oandregal added [Block] Image Affects the Image Block [Block] Pattern Affects the Patterns Block [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced and removed [Block] Pattern Affects the Patterns Block labels Aug 16, 2022
@oandregal oandregal requested a review from ntsekouras August 16, 2022 17:12
@oandregal
Copy link
Member Author

I've tried this with an external image (only url att) and with an image from the media library (id and url atts). Both work well with the pattern I'm using for testing purposes:

<?php
/**
 * Title: demo pattern
 * Slug: twentytwentytwo/demo-pattern
 * Categories: text
 * Block Types: core/paragraph, core/image
 */
?>

<!-- wp:paragraph {"backgroundColor":"pale-cyan-blue"} -->
<p class="has-pale-cyan-blue-background-color has-background">hi rigatonious</p>
<!-- /wp:paragraph -->
<!-- wp:image {"style":{"border":{"width":"18px"}},"className":"is-style-rounded"} -->
<figure class="wp-block-image has-custom-border is-style-rounded"><img src="https://images.unsplash.com/photo-1544005313-94ddf0286df2?ixlib=rb-1.2.1&amp;ixid=MnwxMjA3fDB8MHxzZWFyY2h8NHx8cGVyc29ufGVufDB8fDB8fA%3D%3D&amp;w=1000&amp;q=80" alt="" style="border-width:18px"/></figure>
<!-- /wp:image -->

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@oandregal
Copy link
Member Author

I've been thinking on situations in which this could break the "transform to pattern" feature. I've found none.

In theory, one use case that could render a failure is this:

  • the source block image is an external image (only url att, no id att)
  • the target pattern image only has the id attribute

In this case, because of how the transforms to pattern works, the resulting image would have the url of the source image and teh id of the pattern.

In practice, though, I can't see this happening: the pattern would need to provide an ID for the site's media library, which changes from site to site.

@oandregal
Copy link
Member Author

I've just tried what happens when an image has a wrong ID. The block appears as invalid:

Captura de ecrã de 2022-08-17 16-24-00

So, in the very unlikely situation the above can happen, the resulting state is that the user ends up with an image that is invalid and that can self-correct by clicking "Attempt block recovery". I think this is a fairly safe situation.

@oandregal oandregal merged commit daf1379 into trunk Aug 17, 2022
@oandregal oandregal deleted the add/content-role-to-image-atts branch August 17, 2022 14:26
@github-actions github-actions bot added this to the Gutenberg 14.0 milestone Aug 17, 2022
@ntsekouras
Copy link
Contributor

ntsekouras commented Aug 17, 2022

In practice, though, I can't see this happening: the pattern would need to provide an ID for the site's media library, which changes from site to site.

Exactly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Image Affects the Image Block [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced Needs User Documentation Needs new user documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants